﻿using BCCommon;
using BCData.OA.Reimbursement;
using BCDto.MySql.Admin;
using BCDto.OA.Reimbursement;
using BCService.Utils;
using System;
using System.Collections.Generic;

namespace BCService.OA.ReimbursementRecord
{
    /// <summary>
    /// 报销记录信息
    /// </summary>
    public class ReimbursementRecordService : IReimbursementRecordService
    {

        private readonly IReimbursementRecordData reimbursementRecordData;

        public ReimbursementRecordService(IReimbursementRecordData reimbursementRecordData)
        {
            this.reimbursementRecordData = reimbursementRecordData;
        }

        /// <summary>
        /// 分页获取OA报销申请记录(列表)
        /// </summary>
        /// <param name="adminDto">当前登录管理员</param>
        /// <param name="departmentName">部门名称</param>
        /// <param name="adminName">员工名称</param>
        /// <param name="start">申请时间开始</param>
        /// <param name="end">申请时间结束</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="isMyApproved">是否我审批的</param>
        /// <returns></returns>
        public PageableList<ReimbursementRecordDto> Query(AdminDto adminDto, string departmentName, string adminName, DateTime? start, DateTime? end, bool? ascending, int pageIndex, int pageSize, string sortName, bool? isMyApproved = null)
        {
            var (datas, dataCount) = reimbursementRecordData.GetListAsync(adminDto.AdminId, departmentName, adminName, start, end, ascending, pageIndex, pageSize, sortName, isMyApproved, adminDto.IsSystemAccount ? (int?)null : adminDto.CompanyId).GetAwaiter().GetResult();
            return new PageableList<ReimbursementRecordDto>
            {
                Count = dataCount,
                Items = datas.As<List<ReimbursementRecordDto>>()
            };
        }
    }
}
